Add allow_denser kwarg for direct decompression into denser SparseMatrixCSC#224
Add allow_denser kwarg for direct decompression into denser SparseMatrixCSC#224
allow_denser kwarg for direct decompression into denser SparseMatrixCSC#224Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #224 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 15 15
Lines 1758 1816 +58
=========================================
+ Hits 1758 1816 +58 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Todo:
|
allow_denser kwarg for direct decompression into denser SparseMatrixCSC
|
@amontoison moving this from "enabled by default" to "enabled on demand" took a bit more work than expected, and I had to add a lot more tests to be confident. I wouldn't mind another round of review |
c5374e3 to
3911136
Compare
src/matrices.jl
Outdated
| B::Union{SparseMatrixCSC,SparsityPatternCSC}, | ||
| ) | ||
| return size(A) == size(B) && nnz(A) == nnz(B) | ||
| same_pattern(A::AbstractMatrix, S; allow_denser::Bool=false) = true |
There was a problem hiding this comment.
I think we should rename this function.
compatible_sparsity_pattern or compatible_pattern is probably a better name.
|
@gdalle function decompress!(A::SparseMatrixCSC, B::AbstractMatrix, result::ColumnColoringResult)
(; compressed_indices) = result
S = result.bg.S2
nzA = nonzeros(A)
if nnz(A) == nnz(S)
for k in eachindex(compressed_indices)
nzA[k] = B[compressed_indices[k]]
end
elseif nnz(A) > nnz(S)
rvA, rvS = rowvals(A), rowvals(S)
shift = 0
for j in axes(S, 2)
for k in nzrange(S, j)
i = rvS[k]
found = false
while (k + shift) < A.colptr[j+1] && !found
if rvA[k + shift] == i
found = true
nzA[k + shift] = B[compressed_indices[k]]
else
shift += 1
nzA[k + shift] = zero(eltype(A))
end
end
!found && error("...")
end
end
nzA[(nnz(S) + shift + 1):end] .= zero(eltype(A))
else
error("...")
end
return A
end |
|
Unfortunately I think your version is incorrect: it doesn't account for the fact that we could find a coefficient |
allow_denser kwarg for direct decompression into denser SparseMatrixCSCallow_denser kwarg for direct decompression into denser SparseMatrixCSC
|
Following the discussion in SciML/OrdinaryDiffEq.jl#2653 (comment), this is put on hold for the time being. Let's not delete the branch in case we need it again. |
Fix for SciML/OrdinaryDiffEq.jl#2653 (comment)
User-facing changes
allow_denserto the constructorsGreedyColoringAlgorithmandConstantColoringAlgorithmdecompress!docstring: it allows for decompression into aA::SparseMatrixCSCwith more nonzeros than the sparsity patternSused for coloring.:direct:rowor:columnInternal changes
allow_denserto the result typesdecompress!, implement decompression into a denser matrix by stepping faster through the nonzeros ofAthan through the nonzeros ofS(using an integershift)check_patternto allow for more nonzeros ifallow_denser=truecheck_patternverification to bidirectional decompression. Now the places where users could screw up the sparsity pattern and not notice are: